<template>
    <div ref="pieChart" style="width: 100%; height: 300px;"></div>
  </template>

  <script setup>
  import { ref, onMounted, onUnmounted } from 'vue'
  import * as echarts from 'echarts'

  const pieChart = ref(null)
  let chart = null

  const initChart = () => {
    const chartDom = pieChart.value
    chart = echarts.init(chartDom)

    const option = {
      title: {
        text: '咨询师预约总量占比',
        left: 'center'
      },
      tooltip: {
        trigger: 'item',
        formatter: '{b}: {c} ({d}%)'
      },
      legend: {
        orient: 'horizontal',
        bottom: '5%'
      },
      series: [
        {
          type: 'pie',
          radius: '50%',
          data: [
            { value: 100, name: '张三' },
            { value: 150, name: '李四' },
            { value: 134, name: '王五' },
            { value: 135, name: '赵六' },
            { value: 136, name: '钱七' }
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    }

    chart.setOption(option)
  }

  // 监听窗口大小变化
  const handleResize = () => {
    chart && chart.resize()
  }

  onMounted(() => {
    initChart()
    window.addEventListener('resize', handleResize)
  })

  onUnmounted(() => {
    window.removeEventListener('resize', handleResize)
    chart && chart.dispose()
  })
  </script>

  <style scoped>
  /* 可以添加自定义样式 */
  </style>
